<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/logo.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/logo.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/logo.png">
  <link rel="mask-icon" href="/images/logo.png" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/","scheme":"Pisces","version":"7.7.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"./public/search.xml"};
  </script>

  <meta name="description" content="click look more">
<meta property="og:type" content="article">
<meta property="og:title" content="面试（1）">
<meta property="og:url" content="https://gitee.com/mamba666/mamba666.git/2020/07/23/%E9%9D%A2%E8%AF%95%E9%A2%98%EF%BC%881%EF%BC%89/index.html">
<meta property="og:site_name" content="共你云雨">
<meta property="og:description" content="click look more">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-07-23T08:38:17.542Z">
<meta property="article:modified_time" content="2020-07-24T04:35:33.522Z">
<meta property="article:author" content="Edison">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://gitee.com/mamba666/mamba666.git/2020/07/23/%E9%9D%A2%E8%AF%95%E9%A2%98%EF%BC%881%EF%BC%89/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true
  };
</script>

  <title>面试（1） | 共你云雨</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>
	<a href="https://github.com/mamba666" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">共你云雨</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/mamba666/mamba666.git/2020/07/23/%E9%9D%A2%E8%AF%95%E9%A2%98%EF%BC%881%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Edison">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="共你云雨">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          面试（1）
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-23 16:38:17" itemprop="dateCreated datePublished" datetime="2020-07-23T16:38:17+08:00">2020-07-23</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-07-24 12:35:33" itemprop="dateModified" datetime="2020-07-24T12:35:33+08:00">2020-07-24</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E9%9D%A2%E8%AF%95/" itemprop="url" rel="index"><span itemprop="name">面试</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>click look more</p>
<a id="more"></a>

<h1 id="原生JS继承如何实现"><a href="#原生JS继承如何实现" class="headerlink" title="原生JS继承如何实现"></a>原生JS继承如何实现</h1><blockquote>
<p>翻看es6笔记</p>
</blockquote>
<ul>
<li><p>首先实现两个构造函数，使Child继承Parent</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Parent</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">this</span>.animals = <span class="string">'animals'</span>;</span><br><span class="line">    <span class="keyword">this</span>.show = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="keyword">this</span>.animals);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">Parent.prototype.pro = <span class="string">'pro'</span>;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Child</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">this</span>.dog = <span class="string">'dog'</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用prototype继承</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Child.prototype=<span class="keyword">new</span> Parent()</span><br><span class="line"><span class="comment">// 在执行上一个代码后，Child的原型已经指向了Parent，所以还需要一步操作将Child指向自身</span></span><br><span class="line">Child.prototype.constructor=Child</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用call</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 缺陷就是访问不到Parent.prototype的属性</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Child</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    Parent.call(<span class="keyword">this</span>);</span><br><span class="line">    <span class="keyword">this</span>.dog = <span class="string">'dog'</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h1 id="es6里面有什么类和方法"><a href="#es6里面有什么类和方法" class="headerlink" title="es6里面有什么类和方法"></a>es6里面有什么类和方法</h1><p>没什么好说的，还是看es6笔记</p>
<h1 id="jquey和vue的区别"><a href="#jquey和vue的区别" class="headerlink" title="jquey和vue的区别"></a>jquey和vue的区别</h1><p>最明显的区别就是，jquey是操作DOM，而vue则是操作数据。</p>
<p>vue.js专注于mvvm框架的vm（viewmodel）层，通过双向绑定，将视图和数据联系起来。从而可以通过对数据的操作就可以让视图发生改变。</p>
<h1 id="vue的父子组件和兄弟组件如何传值"><a href="#vue的父子组件和兄弟组件如何传值" class="headerlink" title="vue的父子组件和兄弟组件如何传值"></a>vue的父子组件和兄弟组件如何传值</h1><h2 id="父–-gt-子"><a href="#父–-gt-子" class="headerlink" title="父–&gt;子"></a>父–&gt;子</h2><blockquote>
<p>在父组件中使用v-bind传递数据，在子组件中使用props接收数据，然后使用插值表达式使用数据<br>还有一个注意点，props是单向绑定的：即父可以传递数据影响子组件，但是不能反过来子组件影响父组件。这是为了防止子组件修改父组件的状态。所以不应该在子组件中修改 props 中的值，不然 Vue 发出警告。</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--父传递--&gt;</span><br><span class="line">&lt;router :msg&#x3D;&quot;msg&quot;&gt;&lt;&#x2F;router&gt;</span><br><span class="line">&lt;!--子接收--&gt;</span><br><span class="line">&lt;p&gt;&#123;&#123;msg&#125;&#125;&lt;&#x2F;p&gt;</span><br><span class="line"></span><br><span class="line">export default &#123;</span><br><span class="line">    name:&quot;xx&quot;,</span><br><span class="line">    props:&#123;</span><br><span class="line">        msg:String</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="子–-gt-父"><a href="#子–-gt-父" class="headerlink" title="子–&gt;父"></a>子–&gt;父</h2><blockquote>
<p>子组件通过this.$emit()的方式将值传递给父组件。然后父组件通过v-on去接收</p>
</blockquote>
<p>子：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;button @click&#x3D;&quot;cyy&quot;&gt;按钮&lt;&#x2F;button&gt;</span><br><span class="line">methods: &#123;</span><br><span class="line">    cyy() &#123;</span><br><span class="line">     &#x2F;&#x2F;xxx: 是父组件指定的传数据绑定的函数，yyy:子组件给父组件传递的数据</span><br><span class="line">      this.$emit(&quot;xxx&quot;, &quot;yyy&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<p>父：yyy数据传递给了hehe函数的参数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;router  v-on:xxx&#x3D;&quot;hehe&quot;&gt;&lt;&#x2F;router&gt;</span><br><span class="line">methods: &#123;</span><br><span class="line">   hehe: function(data) &#123;</span><br><span class="line">     console.log(data); &#x2F;&#x2F; yyy</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="兄弟组件传值"><a href="#兄弟组件传值" class="headerlink" title="兄弟组件传值"></a>兄弟组件传值</h2><h3 id="父组件中转"><a href="#父组件中转" class="headerlink" title="父组件中转"></a>父组件中转</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;div&gt; &#x2F;&#x2F;爸爸A</span><br><span class="line">    &lt;router&gt;&lt;&#x2F;router&gt;    &#x2F;&#x2F;哥哥A1</span><br><span class="line">    &lt;vuex&gt;&lt;&#x2F;vuex&gt;　　　　&#x2F;&#x2F;弟弟A2</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>

<p>即首先让A1使用$emit传递到父组件A，然后A使用v-bind传递数据，A2在使用props接收数据</p>
<h3 id="Bus中央事件总线"><a href="#Bus中央事件总线" class="headerlink" title="Bus中央事件总线"></a>Bus中央事件总线</h3><p>还是一样的结构，父A，子为兄弟A1A2</p>
<p>A1:<code>&lt;button @click=&quot;cyy&quot;&gt;按钮&lt;/button&gt; 点击按钮向弟弟A2传值</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> Bus <span class="keyword">from</span> <span class="string">"../api/Bus"</span>;   <span class="comment">//注意引入</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">  data() &#123;</span><br><span class="line">    <span class="keyword">return</span> &#123;</span><br><span class="line">      a: <span class="number">1</span></span><br><span class="line">    &#125;;</span><br><span class="line">  &#125;,</span><br><span class="line">  methods: &#123;</span><br><span class="line">    cyy() &#123;</span><br><span class="line">      Bus.$emit(<span class="string">"zifu"</span>, <span class="keyword">this</span>.a++, <span class="string">"子组件向兄弟组件传值"</span>);    <span class="comment">//存 Bus.$emit</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>A2:<code>&lt;p&gt;接受兄弟A1传值=-------第次,向&lt;/p&gt;</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> Bus <span class="keyword">from</span> <span class="string">"../api/Bus"</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">  data() &#123;</span><br><span class="line">    <span class="keyword">return</span> &#123;</span><br><span class="line">      ccc: <span class="string">""</span>,</span><br><span class="line">      ddd: <span class="string">""</span></span><br><span class="line">    &#125;;</span><br><span class="line">  &#125;,</span><br><span class="line">  created() &#123;</span><br><span class="line">    Bus.$on(<span class="string">"zifu"</span>, (val, val1) =&gt; &#123;    <span class="comment">//取  Bus.$on</span></span><br><span class="line">      <span class="keyword">this</span>.ccc = val;</span><br><span class="line">      <span class="keyword">this</span>.ddd = val1;</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h1 id="vuex和axios的使用"><a href="#vuex和axios的使用" class="headerlink" title="vuex和axios的使用"></a>vuex和axios的使用</h1><h2 id="vuex"><a href="#vuex" class="headerlink" title="vuex"></a>vuex</h2><h3 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h3><blockquote>
<p>以可通过之前做的去哪儿，引申出来vuex的使用。</p>
</blockquote>
<p>有一个场景，就是所在地的需求，即在城市选择页面选择的城市，会同步到首页，这是不同的组件，所以这里使用了vuex去管理这个数据。</p>
<p>还有两个例子:</p>
<ol>
<li>比如说用户的登录信息。就跟微博一样，如果你不登陆，在所有页面上你所使用的功能都会受到限制，那么它们是如何知道你是否登录了呢？这就是多个视图需要依赖这个登录状态信息。</li>
<li>还是登录信息，假设你要退出登录，但是你登录的信息保存在登录页，但是退出需要到退出页面，这就是在另一个视图需要改变同一个登录状态信息。</li>
</ol>
<h3 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h3><ol>
<li>每一个vuex的核心就是一个store，store实际上就是一个容器，用来包含绝大多数的state。所以先创建一个store。</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> store=Vuex.Store(&#123;</span><br><span class="line">	<span class="comment">//存放的数据，但是要牢记，不能直接改变它</span></span><br><span class="line">	state:&#123;</span><br><span class="line">		count:<span class="number">0</span></span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="comment">//用来改变state</span></span><br><span class="line">	mutaions:&#123;</span><br><span class="line">		increase(state)&#123;</span><br><span class="line">			count++</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>接着就可以进行操作了</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">store.commit(<span class="string">"increase"</span>) <span class="comment">// 即通过commit方法调用mutations里面的increase方法</span></span><br><span class="line">store.state<span class="comment">//1</span></span><br></pre></td></tr></table></figure>

<p>为什么要使用actions呢？直接mutations不是更方便？<br>这是因为mutations的操作都是同步的，而js又涉及到很多一步操作，所以就使用actions操作异步。</p>
<ol start="2">
<li>上面操作了state，那么如何在组件中获取到state</li>
</ol>
<blockquote>
<p>通过在根实例中注册store，该store实例会注入到根组件下的所有子组件中，可以通过 this.$store.state去访问state</p>
</blockquote>
<p>当vuex的state数据过多，那么可以使用mapState辅助函数。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123;mapState&#125; <span class="keyword">from</span> <span class="string">"vuex"</span></span><br><span class="line"><span class="comment">// 使用mapState,此时，city已经被映射了，所以可以直接使用this.city去获取属性值</span></span><br><span class="line">computed:&#123;</span><br><span class="line">    <span class="comment">//意思是将vuex中的city数据映射到组件的computed属性里</span></span><br><span class="line">    ...mapState([<span class="string">"city"</span>])</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//还有一种使用方法,意思是将store里面的state里面的city属性映射到computed属性中的currentCity中。即currentCity代表了$store.state.city</span></span><br><span class="line">computed:&#123;</span><br><span class="line">        ...mapState(&#123;</span><br><span class="line">            currentCity:<span class="string">"city"</span></span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>使用getter</li>
</ol>
<p>getter实际上就是store额计算属性，并且还会被缓存下来</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> store=vuex.Store(&#123;</span><br><span class="line">	state:&#123;</span><br><span class="line">		price:<span class="number">10</span>,</span><br><span class="line">		num:<span class="number">20</span></span><br><span class="line">	&#125;,</span><br><span class="line">	getters:&#123;</span><br><span class="line">		total:<span class="function"><span class="params">state</span>=&gt;</span>&#123;</span><br><span class="line">			<span class="keyword">return</span> state.price*state.num</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>那么如何在组件中使用total数据呢？</p>
<ol>
<li><p>通过属性访问<br><code>this.$store.getters.total</code></p>
</li>
<li><p>通过方法访问<br><code>this.$store.gettes.total()</code></p>
</li>
</ol>
<h1 id="es6里面const、let、var的区别"><a href="#es6里面const、let、var的区别" class="headerlink" title="es6里面const、let、var的区别"></a>es6里面const、let、var的区别</h1><ul>
<li>let 和 const都不能重复声明一个变量，但是var可以</li>
<li>let 和 const声明的变量，在块级内会存在暂时性死区，即它所声明的变量就“绑定”（binding）这个区域，不再受外部的影响。</li>
<li>var 和 let声明时，可以不赋值，但是const必须赋值</li>
</ul>
<h2 id="关于const的本质"><a href="#关于const的本质" class="headerlink" title="关于const的本质"></a>关于const的本质</h2><p>const并非说值不能改变，而是变量指向的那个内存地址所保存的数据不能改动。<br>对于字符串、数值、布尔值这种简单的数据结构，就等同于常量<br>但是对于复杂的数据，比如对象、数组。变量指向的内存地址，保存的只是一个指向实际数据的指针，const 只能保证这个指针是固定的，至于它指向的数据结构是不是可变的，就完全不能控制了。</p>
<h1 id="js里的垃圾回收机制"><a href="#js里的垃圾回收机制" class="headerlink" title="js里的垃圾回收机制"></a>js里的垃圾回收机制</h1><p>js是通过检测一个对象，是否还会被使用，假如确定不在使用了，那么就会清除这个内存。<br>一般常见的方法就是标记清除。即当变量进入环境时，就将这个变量标记为“进入环境”，反之就是“离开环境”</p>
<h1 id="如何使用js调bug"><a href="#如何使用js调bug" class="headerlink" title="如何使用js调bug"></a>如何使用js调bug</h1><ol>
<li>使用浏览器开发者模式</li>
<li>使用vscode Debug模式</li>
</ol>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/07/16/react%E6%8C%89%E9%9C%80%E5%BC%95%E5%85%A5antd/" rel="prev" title="react按需引入antd">
      <i class="fa fa-chevron-left"></i> react按需引入antd
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/07/24/%E9%9D%A2%E8%AF%95%E9%A2%98%EF%BC%882%EF%BC%89/" rel="next" title="面试（2）">
      面试（2） <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#原生JS继承如何实现"><span class="nav-number">1.</span> <span class="nav-text">原生JS继承如何实现</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#es6里面有什么类和方法"><span class="nav-number">2.</span> <span class="nav-text">es6里面有什么类和方法</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#jquey和vue的区别"><span class="nav-number">3.</span> <span class="nav-text">jquey和vue的区别</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#vue的父子组件和兄弟组件如何传值"><span class="nav-number">4.</span> <span class="nav-text">vue的父子组件和兄弟组件如何传值</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#父–-gt-子"><span class="nav-number">4.1.</span> <span class="nav-text">父–&gt;子</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#子–-gt-父"><span class="nav-number">4.2.</span> <span class="nav-text">子–&gt;父</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#兄弟组件传值"><span class="nav-number">4.3.</span> <span class="nav-text">兄弟组件传值</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#父组件中转"><span class="nav-number">4.3.1.</span> <span class="nav-text">父组件中转</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Bus中央事件总线"><span class="nav-number">4.3.2.</span> <span class="nav-text">Bus中央事件总线</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#vuex和axios的使用"><span class="nav-number">5.</span> <span class="nav-text">vuex和axios的使用</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#vuex"><span class="nav-number">5.1.</span> <span class="nav-text">vuex</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#概念"><span class="nav-number">5.1.1.</span> <span class="nav-text">概念</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用"><span class="nav-number">5.1.2.</span> <span class="nav-text">使用</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#es6里面const、let、var的区别"><span class="nav-number">6.</span> <span class="nav-text">es6里面const、let、var的区别</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#关于const的本质"><span class="nav-number">6.1.</span> <span class="nav-text">关于const的本质</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#js里的垃圾回收机制"><span class="nav-number">7.</span> <span class="nav-text">js里的垃圾回收机制</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#如何使用js调bug"><span class="nav-number">8.</span> <span class="nav-text">如何使用js调bug</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Edison</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">124</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">21</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
</div>
  <div class="powered-by">山高水远  一定相见
  </div>
<div></div>
<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">至今已写107.1k字</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
